package com.ship.contract.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.BaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import lombok.Data;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 调度优化方案详情
 *
 * @author AbyssRabbit@163.com
 * @since 2023-10-17
 */
@Data
@TableName("sp_arrange_scheme_detail")
public class SpArrangeSchemeDetail extends BaseBean implements Joinable {

    /**
     * 方案ID
     */
    private Long schemeId;

    /**
     * 方案编号
     */
    private Integer schemeNumber;

    /**
     * 航次号
     */
    @Label(value = "航次号")
    @TableColumn
    private String voyageNo;

    /**
     * 货号
     */
    @Label(value = "货号")
    @TableColumn
    private String goodsNum;

    /**
     * 资源合同ID
     */
    private Long resourceContract;

    /**
     * 装载港id
     */
    private Long expectedLoadingPortId;

    /**
     * 卸载港id
     */
    private Long expectedUnloadingPortId;

    /**
     * 合同装载量单位(1:MMBtu,2:m³,3:MT)
     */
    private Integer loadingCapacityUnit;

    /**
     * 舱容（单位：立方米）
     */
    private BigDecimal storageCapacity;

    /**
     * 舱容（单位：立方米）
     */
    @Label(value = "舱容")
    @TableColumn
    @SearchItem
    @TableField(exist = false)
    private String storageCapacityString;

    public String getStorageCapacityString(){
        String result = null;
        if (getStorageCapacity()!=null){
            DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
            result = decimalFormat.format(getStorageCapacity());
            result = result+" m³";}
        return result;
    }

    /**
     * 是否为FOB销售船货
     */
    private Integer isFobSell;

    /**
     * 前空挡天数
     */
    @Label(value = "前空挡天数")
    private Integer frontDays;

    /**
     * 后空挡天数
     */
    @Label(value = "后空挡天数")
    private Integer backDays;

    /**
     * 资源合同名称
     */
    @Label(value = "资源合同")
    @TableColumn
    private String contractName;

    /**
     * 资源方（资源合同中的卖方）
     */
    @Label(value = "资源方",multiSelect = true)
    @SearchItem
    @TableColumn
    private String seller;

    @TableField(exist = false)
    private String sellerListForSearch;

    /**
     * 贸易类型(资源合同中的贸易类型）
     */
    @Label(value="贸易类型",enumContent = "贸易类型",multiSelect = true)
    @SearchItem
//    @TableColumn
    private Integer tradeType;

    @Label(value="贸易类型",enumContent = "贸易类型",multiSelect = true)
    @SearchItem
    @TableColumn
    @TableField(exist = false)
    private String tradeTypeStr;

    public String getTradeTypeStr() {
        String tradeTypeStr = null;
        if (null != this.getTradeType()){
            if (1 == this.getTradeType()){
                tradeTypeStr = "长协";
            }
            if (2 == this.getTradeType()){
                tradeTypeStr = "中期";
            }
            if (3 == this.getTradeType()){
                tradeTypeStr = "现货";
            }
        }
        return tradeTypeStr;
    }

    @TableField(exist = false)
    private String tradeTypeListForSearch;

    /**
     * 贸易主体
     */
    @Label(value="贸易主体",enumContent = "贸易主体",multiSelect = true)
    @SearchItem
//    @TableColumn
    private Integer tradeBody;

    @Label(value="贸易主体",enumContent = "贸易主体",multiSelect = true)
    @SearchItem
    @TableColumn
    @TableField(exist = false)
    private String tradeBodyStr;

    public String getTradeBodyStr() {
        String tradeBodyStr = null;
        if (null != this.getTradeType()){
            if (1 == this.getTradeBody()){
                tradeBodyStr = "国贸";
            }
            if (2 == this.getTradeBody()){
                tradeBodyStr = "新贸";
            }
        }
        return tradeBodyStr;
    }

    @TableField(exist = false)
    private String tradeBodyListForSearch;

    /**
     * 预计装载时间
     */
    @Label(value = "预计装载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingDate;

    /**
     * 预计装载完成窗口
     */
    @Label(value = "预计装载完成时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingCompletionWindow;

    /**
     * 实际装载时间
     */
    @Label(value = "实际装载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date realityLoadingDate;

    /**
     * 预计装载港
     */
    @Label(value = "装载港",multiSelect = true)
    @SearchItem
    @TableColumn
    private String expectedLoadingPort;

    @TableField(exist = false)
    private String expectedLoadingPortListForSearch;

    /**
     * 船名
     */
    @Label(value = "船名",multiSelect = true)
    @SearchItem
    @TableColumn
    private String shipName;

    @TableField(exist = false)
    private String shipNameListForSearch;

    /**
     * IMO
     */
    @Label(value = "IMO",multiSelect = true)
    @SearchItem
    @TableColumn
    private String imo;

    @TableField(exist = false)
    private String imoListForSearch;

    /**
     * 巴拿马运河预定时间
     */
    @Label(value = "巴拿马运河预定时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date panamaCanalReservationDate;

    /**
     * 换船时间1
     */
    @Label(value = "换船时间1")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date shipChangeDateOne;

    /**
     * 换船时间2
     */
    @Label(value = "换船时间2")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date shipChangeDateTwo;

    /**
     * 换港时间1
     */
    @Label(value = "换港时间1")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date portChangeDateOne;

    /**
     * 换港时间2
     */
    @Label(value = "换港时间2")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date portChangeDateTwo;

    /**
     * 合同装载量
     */
    private BigDecimal loadingCapacity;

    /**
     * 预计卸载港
     */
    @Label(value = "预计卸载港",multiSelect = true)
    @SearchItem
    @TableColumn
    private String expectedUnloadingPort;

    @TableField(exist = false)
    private String expectedUnloadingPortListForSearch;

    /**
     * 预计满载航程天数
     */
    @Label(value = "预计满载航程天数")
    @TableColumn
    private Integer expectedFullLoadVoyageDays;

    /**
     * 预计卸载窗口
     */
    @Label(value = "预计卸载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingWindow;

    /**
     * 预计卸载完成窗口
     */
    @Label(value = "预计卸载完成时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingCompletionWindow;

    /**
     * 预计空载航程天数
     */
    @Label(value = "预计空载航程天数")
    @TableColumn
    private Integer expectedEmptyLoadVoyageDays;

    /**
     * 实际卸载时间
     */
    @Label(value = "实际卸载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date realityUnloadingDate;

    /**
     * 实际卸载地
     */
    @Label(value = "实际卸载地")
    @TableColumn
    private String realityLoadingPort;

    /**
     * FOB补货方案详情ID
     */
    private Long fobSchemeDetailId;

    /**
     * DES补货装载量
     */
    private BigDecimal desGoodsQuantity;

    /**
     * DES补货采购价格
     */
    private BigDecimal desGoodsPrice;

    /**
     * fob补货利润率
     */
    private BigDecimal fobRestockProfit;

    /**
     * des补货利润率
     */
    private BigDecimal desRestockProfit;

    /**
     * 合同卸载量
     */
    private BigDecimal contractUnloadingCapacity;

    /**
     * 实际卸载量
     */
    private BigDecimal realityUnloadingCapacity;

    /**
     * 实际装载量
     */
    private BigDecimal realityLoadingCapacity;

    /**
     * 实际卸载量
     */
    @Label(value = "实际卸载量")
    @TableColumn
    @SearchItem
    @TableField(exist = false)
    private String realityUnloadingCapacityStr;

    public String getRealityUnloadingCapacityStr(){
        String result = null;
        if (getRealityUnloadingCapacity() !=null){
            DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
            result = decimalFormat.format(getRealityUnloadingCapacity());
            result = result+" MMBtu";}
        return result;
    }

    /**
     * 实际装载量
     */
    @Label(value = "实际装载量")
    @TableColumn
    @TableField(exist = false)
    private String realityLoadingCapacityStr;

    public String getRealityLoadingCapacityStr(){
        String result = null;
        if (getRealityLoadingCapacity()!=null){
            DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
            result = decimalFormat.format(getRealityLoadingCapacity());
            result = result+" MMBtu";}
        return result;
    }

    /**
     * 资源合同价格（采购价格，美元）
     */
    @Label(value = "资源合同价格（采购价格，美元）")
    private BigDecimal conPrice;

    /**
     * 国内销售价格，美元
     */
    @Label(value = "国内销售价格，美元")
    private BigDecimal sellPrice;

    /**
     * 贸易利润，美元
     */
    @Label(value = "贸易利润，美元")
    private BigDecimal tradingProfit;

//    /**
//     * 预计空载返程窗口
//     */
//    @Label(value = "预计空载返程窗口")
//    @TableColumn
//    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
//    private Date expectedEmptyReturnWindow;

    /**
     * 船速（节）
     */
    private BigDecimal shipSpeed;

    /**
     * 货量单位
     */
    @Label(value = "货量单位",enumContent = "装卸载量单位",multiSelect = true)
    private Integer quantityUnit;

    /**
     * 单个船装载货量
     */
    private BigDecimal singleGoodsQuantity;

    /**
     * 油耗
     */
    private BigDecimal oilConsumption;

    /**
     * 航线
     */
    private String shipRoute;

    /**
     * 航运合同名称
     */
    private String shipContractName;

    /**
     * 航运合同贸易主体(国贸、新贸)
     */
    private Integer shipTradeBody;

    /**
     * 印度空载航程天数
     */
    private Integer indiaEmptyLoadDays;

    /**
     * 欧洲空载航程天数
     */
    private Integer europeEmptyLoadDays;


    /**
     * 船运合同id
     */
    private Long shipContractId;

    /**
     * 计划id
     */
    @Label(value = "计划id")
    private Long planId;

    /**
     * 船运合同类型（租入长期船、租入短期船、船舶租出、内部转租）
     */
    @Label(value="合同类型",enumContent = "船运合同类型",multiSelect = true)
    private Integer shipContractType;

    /**
     * 审批，1：未审批，2：已审批
     */
    private Integer schemeApprove;

    /**
     * 上一次的更新的方案详情ID
     */
    private Long lastDetailId;

    /**
     * 时间
     */
    @TableField(exist = false)
    private Integer days;

    /**
     * 运费
     */
    @TableField(exist = false)
    private BigDecimal freight;

    /**
     * 贸易利润率
     */
    @TableField(exist = false)
    private BigDecimal trade;

    /**
     * 船舶利用率
     */
    @TableField(exist = false)
    private BigDecimal ship;

    /**
     * 装载量格式化
     */
    @TableField(exist = false)
    private String singleGoodsQuantityString;

    public String getSingleGoodsQuantityString(){
        String result = null;
        if (getSingleGoodsQuantity()!=null){
            DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
            result = decimalFormat.format(getSingleGoodsQuantity());
            result = result+" MMBtu";}
        return result;
    }

    /**
     * 油耗格式化
     */
    @TableField(exist = false)
    private String oilConsumptionString;

    /**
     * 舱容格式化
     */
    @TableField(exist = false)
    @Label(value = "合同装载量")
    @TableColumn
    @SearchItem
    private String loadingCapacityString;

    public String getLoadingCapacityString(){
        String result = null;
        if (getLoadingCapacity()!=null){
            DecimalFormat decimalFormat = new DecimalFormat("#,###.###");
            result = decimalFormat.format(getLoadingCapacity());
            if(getLoadingCapacityUnit() != null){
                result = (result + (getLoadingCapacityUnit().intValue() == 1 ? " MMBtu"
                        : (getLoadingCapacityUnit().intValue() == 2 ? " m³" : " MT")));
            }
        }
        return result;
    }

    /**
     * 资源类型（1：现货，2：潜在投标）
     */
    private Integer isPotential;

    /**
     * 资源合同ID（销售）
     */
    private Long sellerResourceContract;

    /**
     * 资源合同名称（销售）
     */
    private String sellerContractName;

    /**
     * 年度计划年份
     */
    private String buyer;

    /**
     * 起租开始时间
     */
    @TableField(exist = false)
    private AtomicReference<Date> startingDateOfLeaseBegin = new AtomicReference<>();
    /**
     * 还船结束时间
     */
    @TableField(exist = false)
    private AtomicReference<Date> redeliveryDateEnd = new AtomicReference<>();
    /**
     * 租出时间，多条
     */
    @TableField(exist = false)
    private List<String> leaseTermStrs = new ArrayList<>();
    /**
     * 货运标识
     */
    @TableField(exist = false)
    private String cargoCode;

    /**
     * 方案执行状态（1：未下发，2：已排布（执行中），3：已完成，4：已终止）
     */
    @Label(value="状态",enumContent = "方案执行状态",multiSelect = true)
//    @SearchItem
//    @TableColumn
    @SearchItem
    private Integer executeStatus;

    @Label(value="状态",enumContent = "方案执行状态",multiSelect = true)
    @TableColumn
    @TableField(exist = false)
    private String executeStatusStr;


    @TableField(exist = false)
    private String executeStatusListForSearch;

    /**
     * 年份
     */
    @Label(value="年度",multiSelect = true)
    @SearchItem
    @TableColumn
    private Integer planYear;

    @TableField(exist = false)
    private String planYearListForSearch;

    /**
     * 运费预算
     */
    private String freightBudget;

    /**
     * 排布类型（1：回国，2：欧洲）
     */
    private Integer layoutType;

    /**
     * 调度方案详情ID
     */
    private Long dispatchSchemeDetailId;

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }
}
